<?php
/**
 * Abstract Class For Controller, also contains useful page functionality
 *
 * @package Mhtml
 * @author Matt Pike
 */
abstract class Controller{

	public $controller	= null;
	public $action		= null;

	/**
	 * Redirect to url
	 *
	 * @param string $url
	 */
	public static function redirect($url){
		@ob_end_clean(); // clear output buffer
		header("HTTP/1.1 301 Moved Permanently");
		header("Location: ". strval($url));
		exit();
	}

	/**
	 * Set content header i.e. "application/json"
	 *
	 * @param string $type
	 */
	public static function setContentType(){
		header("Content-type: $type");
	}

	/**
	 * Load a view file with supplied variables
	 *
	 * @param string $viewPath
	 * @param array $viewVariables
	 * @param boolean $required
	 */
	public static function loadView($viewPath,array $viewVariables=array(), $_required=true){
		$viewPath = ltrim($viewPath,"/");
		extract($viewVariables);
		ob_start();
		if($_required){
			require DirectoryManager::$pathViews."/".$viewPath;
		}else{
			include DirectoryManager::$pathViews."/".$viewPath;
		}
		$viewContents = ob_get_contents();
		ob_end_clean();
		return $viewContents;
	}
}
?>